package logic

import (
	"context"
	table "pd/server/app/pd/data/product"
	form "pd/server/app/pd/form/product"
	model "pd/server/app/pd/model/product"
	"time"
)

var productTable table.ProductTable

type ProductLogic struct {
}

func (this *ProductLogic) Create(ctx context.Context, product *model.ProductModel) (err error) {
	product.CreateTime = time.Now()
	product.LastUpdateTime = time.Now()
	return productTable.Create(ctx, product)
}

func (this *ProductLogic) Update(ctx context.Context, product *model.ProductModel) (err error) {
	product.LastUpdateTime = time.Now()
	return productTable.Update(ctx, product)
}

func (this *ProductLogic) Delete(ctx context.Context, product *model.ProductModel) (err error) {
	return productTable.Delete(ctx, product)
}

func (this *ProductLogic) List(ctx context.Context, frm *form.ListForm) (productList []*model.ProductModel, total int64, err error) {

	return productTable.List(ctx, frm)
}
